package com.hqsc.upms.server.controller.merchant.payment;

import com.alipay.api.*;
import com.alipay.api.domain.TransferDetailResult;
import com.alipay.api.request.*;
import com.alipay.api.response.*;
import com.hqsc.common.util.DateUtils;
import com.hqsc.common.util.RedisUtil;
import com.hqsc.common.util.ResourceUtil;
import com.hqsc.upms.dao.model.YrMerchantCapitalAccount;
import com.hqsc.upms.dao.model.YrPaymentOrder;
import com.hqsc.upms.dao.model.YrTaxSourcePayChannel;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.math.BigDecimal;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * 支付宝接口
 */
public class AliPayment {

    private static final Logger logger = LoggerFactory.getLogger(AliPayment.class);
    //请求格式
    private static final String format = "JSON";
    //编码方式
    private static final String charset = "UTF-8";


    /**
     * 单笔转账接口
     *
     * @param yrPaymentOrder
     * @param yrTaxSourcePayChannel
     * @return
     */

    public static Map<String, Object> uniTransfer(YrPaymentOrder yrPaymentOrder, YrTaxSourcePayChannel yrTaxSourcePayChannel) {

        //yrPaymentOrder.getMerchantOrderNumber();       //订单号
        //yrPaymentOrder.getAmountOfPayment();         //打款金额       打款金额 不能少于0.1元
        //yrPaymentOrder.getReceivingAccount();       //收款人手机号
        //yrPaymentOrder.getNameOfReceiver();         //收款人姓名

        Map<String, Object> map = new HashMap<>();

        try {
            String url = ResourceUtil.getConfigByName("a_li_pay_url");
            //构造client
            CertAlipayRequest certAlipayRequest = new CertAlipayRequest();
            //设置网关地址
            certAlipayRequest.setServerUrl(url);
            //设置应用Id
            certAlipayRequest.setAppId(yrTaxSourcePayChannel.getPatParam3());
            //设置应用私钥
            certAlipayRequest.setPrivateKey(yrTaxSourcePayChannel.getPatParam2());
            //设置请求格式，固定值json
            certAlipayRequest.setFormat(format);
            //设置字符集
            certAlipayRequest.setCharset(charset);
            //设置签名类型
            certAlipayRequest.setSignType(yrTaxSourcePayChannel.getPatParam5());
            //设置应用公钥证书路径
            String app_cert_path = yrTaxSourcePayChannel.getPatParam4();
            certAlipayRequest.setCertPath(app_cert_path);
            //设置支付宝公钥证书路径
            String alipay_cert_path = yrTaxSourcePayChannel.getPatParam6();
            certAlipayRequest.setAlipayPublicCertPath(alipay_cert_path);
            //设置支付宝根证书路径
            String alipay_root_cert_path = yrTaxSourcePayChannel.getReference1();
            certAlipayRequest.setRootCertPath(alipay_root_cert_path);
            //构造client
            AlipayClient alipayClient = new DefaultAlipayClient(certAlipayRequest);
//            AlipayClient alipayClient = new DefaultAlipayClient(serverurl, app_id, private_key, format, charset, alipay_public_key, sign_type);
//            AlipayClient alipayClient = new DefaultAlipayClient(url, yrTaxSourcePayChannel.getPatParam3(), yrTaxSourcePayChannel.getPatParam2(), format, charset, yrTaxSourcePayChannel.getPatParam1(), yrTaxSourcePayChannel.getPatParam5());

            AlipayFundTransUniTransferRequest request = new AlipayFundTransUniTransferRequest();

            request.setBizContent("{" +
                    "\"out_biz_no\":\"" + yrPaymentOrder.getMerchantOrderNumber() + "\"," +
                    "\"trans_amount\":" + yrPaymentOrder.getAmountOfPayment() + "," +
                    "\"product_code\":\"TRANS_ACCOUNT_NO_PWD\"," +
                    "\"biz_scene\":\"DIRECT_TRANSFER\"," +
                    "\"order_title\":\"单笔转账\"," +
                    "\"payee_info\":{" +
                    "\"identity\":\"" + yrPaymentOrder.getReceivingAccount() + "\"," +
                    "\"identity_type\":\"ALIPAY_LOGON_ID\"," +
                    "\"name\":\"" + yrPaymentOrder.getNameOfReceiver() + "\"" +
                    "    }," +
                    "\"remark\":\"单笔转账\"," +
                    "  }");
            logger.info("单笔转账接口传参" + request.getBizContent());
            AlipayFundTransUniTransferResponse response = alipayClient.certificateExecute(request);
            logger.info("单笔转账接口结果" + response.getCode()+response.getSubMsg());
            String code = response.getCode();
            String msg = response.getSubMsg();
            if (StringUtils.isNotBlank(code)) {
                if ("10000".equals(code)) {
                    String status = response.getStatus();
                    if ("SUCCESS".equals(status)) {
                        map.put("code", 1);
                        //支付宝转账订单号
                        map.put("data", response.getOrderId());
                        map.put("payOrderId", response.getPayFundOrderId());
                        //转账成功

                    } else if ("DEALING".equals(status)) {
                        map.put("code", 1);
                        //支付宝转账订单号
                        map.put("data", response.getOrderId());
                        map.put("payOrderId", response.getPayFundOrderId());

                    } else if ("REFUND".equals(status)) {
                        map.put("code", 4);
                        map.put("msg", "支付失败:订单被退票");
                        //转账失败

                    } else {
                        map.put("code", 4);
                        map.put("msg", "支付失败：订单创建失败");
                        //转账失败

                    }
                } else {
                    //业务返回码
                    map.put("code", 4);
                    //业务返回码描述
                    if (StringUtils.isBlank(msg)) {
                        msg = "支付失败";
                    }
                    map.put("msg", msg);
                    //转账失败

                }
            } else {
                map.put("code", 4);
                map.put("msg", "获取返回码失败，支付失败");
                //转账失败

            }

        } catch (Exception e) {
            e.printStackTrace();
            map.put("code", 4);
            map.put("msg", e.getMessage());


        }
        return map;
    }


    /**
     * 转账业务单据查询接口
     *
     * @param yrPaymentOrder
     * @param yrTaxSourcePayChannel
     * @return
     */
    public static Map<String, Object> commonQuery(YrPaymentOrder yrPaymentOrder, YrTaxSourcePayChannel yrTaxSourcePayChannel) {

        //yrPaymentOrder.getCapitalFlowNumber();       //支付宝转账单据号

        Map<String, Object> map = new HashMap<>();

        try {
            String url = ResourceUtil.getConfigByName("a_li_pay_url");
            //构造client
            CertAlipayRequest certAlipayRequest = new CertAlipayRequest();
            //设置网关地址
            certAlipayRequest.setServerUrl(url);
            //设置应用Id
            certAlipayRequest.setAppId(yrTaxSourcePayChannel.getPatParam3());
            //设置应用私钥
            certAlipayRequest.setPrivateKey(yrTaxSourcePayChannel.getPatParam2());
            //设置请求格式，固定值json
            certAlipayRequest.setFormat(format);
            //设置字符集
            certAlipayRequest.setCharset(charset);
            //设置签名类型
            certAlipayRequest.setSignType(yrTaxSourcePayChannel.getPatParam5());
            //设置应用公钥证书路径
            String app_cert_path = yrTaxSourcePayChannel.getPatParam4();
            certAlipayRequest.setCertPath(app_cert_path);
            //设置支付宝公钥证书路径
            String alipay_cert_path = yrTaxSourcePayChannel.getPatParam6();
            certAlipayRequest.setAlipayPublicCertPath(alipay_cert_path);
            //设置支付宝根证书路径
            String alipay_root_cert_path = yrTaxSourcePayChannel.getReference1();
            certAlipayRequest.setRootCertPath(alipay_root_cert_path);
            //构造client
            AlipayClient alipayClient = new DefaultAlipayClient(certAlipayRequest);

            //AlipayClient alipayClient = new DefaultAlipayClient(serverurl, app_id, private_key, format, charset, alipay_public_key, sign_type);
//            AlipayClient alipayClient = new DefaultAlipayClient(url, yrTaxSourcePayChannel.getPatParam3(), yrTaxSourcePayChannel.getPatParam2(), format, charset, yrTaxSourcePayChannel.getPatParam1(), yrTaxSourcePayChannel.getPatParam5());

            AlipayFundTransCommonQueryRequest request = new AlipayFundTransCommonQueryRequest();
            request.setBizContent("{" +
                    "\"order_id\":\"" + yrPaymentOrder.getCapitalFlowNumber() + "\"" +
                    "  }");
            logger.info("转账业务单据查询接口传参" + request.getBizContent());
            AlipayFundTransCommonQueryResponse response = alipayClient.certificateExecute(request);
            logger.info("转账业务单据查询接口结果" + response);

            //网关返回码
            String code = response.getCode();
            //网关返回码描述
            String msg = response.getSubMsg();

            if (StringUtils.isNotBlank(code)) {
                if ("10000".equals(code)) {
                    String status = response.getStatus();
                    if ("SUCCESS".equals(status)) {
                        map.put("code", 1);
                        map.put("msg", response.getSubMsg());
                        //转账成功

                    } else if ("WAIT_PAY".equals(status)) {
                        map.put("code", 5);
                        map.put("msg", "等待支付");

                    } else if ("CLOSED".equals(status)) {
                        map.put("code", 4);
                        map.put("msg", "订单超时关闭");

                    } else if ("REFUND".equals(status)) {
                        map.put("code", 4);
                        map.put("msg", "支付失败:订单被退票");
                        //转账失败

                    } else {
                        map.put("code", 4);
                        map.put("msg", "支付失败：订单创建失败");
                        //转账失败

                    }
                } else {
                    //业务返回码
                    map.put("code", 4);
                    //业务返回码描述
                    if (StringUtils.isBlank(msg)) {
                        msg = "支付失败";
                    }
                    map.put("msg", msg);
                    //转账失败

                }
            } else {
                map.put("code", 5);
                //转账失败
            }

        } catch (Exception e) {
            e.printStackTrace();
            map.put("code", 4);
            map.put("msg", e.getMessage());

        }
        return map;

    }


    /**
     * 申请电子回单接口
     *
     * @param key
     * @param yrTaxSourcePayChannel
     * @return
     */
    public static Map<String, Object> ereceiptApply(String key, YrTaxSourcePayChannel yrTaxSourcePayChannel) {

        //yrPaymentOrder.getCapitalFlowNumber();      //传入账务流水号

        Map<String, Object> map = new HashMap<>();

        try {
            String url = ResourceUtil.getConfigByName("a_li_pay_url");
            //构造client
            CertAlipayRequest certAlipayRequest = new CertAlipayRequest();
            //设置网关地址
            certAlipayRequest.setServerUrl(url);
            //设置应用Id
            certAlipayRequest.setAppId(yrTaxSourcePayChannel.getPatParam3());
            //设置应用私钥
            certAlipayRequest.setPrivateKey(yrTaxSourcePayChannel.getPatParam2());
            //设置请求格式，固定值json
            certAlipayRequest.setFormat(format);
            //设置字符集
            certAlipayRequest.setCharset(charset);
            //设置签名类型
            certAlipayRequest.setSignType(yrTaxSourcePayChannel.getPatParam5());
            //设置应用公钥证书路径
            String app_cert_path = yrTaxSourcePayChannel.getPatParam4();
            certAlipayRequest.setCertPath(app_cert_path);
            //设置支付宝公钥证书路径
            String alipay_cert_path = yrTaxSourcePayChannel.getPatParam6();
            certAlipayRequest.setAlipayPublicCertPath(alipay_cert_path);
            //设置支付宝根证书路径
            String alipay_root_cert_path = yrTaxSourcePayChannel.getReference1();
            certAlipayRequest.setRootCertPath(alipay_root_cert_path);
            //构造client
            AlipayClient alipayClient = new DefaultAlipayClient(certAlipayRequest);

//            AlipayClient alipayClient = new DefaultAlipayClient(serverurl, app_id, private_key, format, charset, alipay_public_key, sign_type);
//            AlipayClient alipayClient = new DefaultAlipayClient(url, yrTaxSourcePayChannel.getPatParam3(), yrTaxSourcePayChannel.getPatParam2(), format, charset, yrTaxSourcePayChannel.getPatParam1(), yrTaxSourcePayChannel.getPatParam5());
            AlipayDataBillEreceiptApplyRequest request = new AlipayDataBillEreceiptApplyRequest();
            request.setBizContent("{" +
                    "\"type\":\"FUND_DETAIL\"," +
                    "\"key\":\"" + key+ "\"" +
                    "}");
            logger.info("申请电子回单接口传参" + request.getBizContent());
            AlipayDataBillEreceiptApplyResponse response = alipayClient.certificateExecute(request);
            logger.info("申请电子回单接口结果" + response);

            //网关返回码
            String code = response.getCode();
            //网关返回码描述
            String msg = response.getSubMsg();

            if (StringUtils.isNotBlank(code)) {
                if ("10000".equals(code)) {
                    //申请成功
                    map.put("code", 1);
                    map.put("msg", response.getSubMsg());
                    map.put("fileId", response.getFileId());
                } else {
                    //申请失败
                    map.put("code", 4);
                    map.put("msg", "申请电子回单失败");
                }
            } else {
                //申请失败
                map.put("code", 4);
                map.put("msg", "获取返回码失败,申请电子回单失败");
            }

        } catch (Exception e) {
            e.printStackTrace();
            map.put("code", 4);
            map.put("msg", e.getMessage());

        }
        return map;
    }


    /**
     * 查询电子回单状态接口
     *
     * @param fileId
     * @param yrTaxSourcePayChannel
     * @return
     */

    public static Map<String, Object> ereceiptQuery(String fileId, YrTaxSourcePayChannel yrTaxSourcePayChannel) {
        Map<String, Object> map = new HashMap<>();

        //String file_id = yrPaymentOrder.getReference17();     //文件申请号file_id信息

        try {
            String url = ResourceUtil.getConfigByName("a_li_pay_url");
            //构造client
            CertAlipayRequest certAlipayRequest = new CertAlipayRequest();
            //设置网关地址
            certAlipayRequest.setServerUrl(url);
            //设置应用Id
            certAlipayRequest.setAppId(yrTaxSourcePayChannel.getPatParam3());
            //设置应用私钥
            certAlipayRequest.setPrivateKey(yrTaxSourcePayChannel.getPatParam2());
            //设置请求格式，固定值json
            certAlipayRequest.setFormat(format);
            //设置字符集
            certAlipayRequest.setCharset(charset);
            //设置签名类型
            certAlipayRequest.setSignType(yrTaxSourcePayChannel.getPatParam5());
            //设置应用公钥证书路径
            String app_cert_path = yrTaxSourcePayChannel.getPatParam4();
            certAlipayRequest.setCertPath(app_cert_path);
            //设置支付宝公钥证书路径
            String alipay_cert_path = yrTaxSourcePayChannel.getPatParam6();
            certAlipayRequest.setAlipayPublicCertPath(alipay_cert_path);
            //设置支付宝根证书路径
            String alipay_root_cert_path = yrTaxSourcePayChannel.getReference1();
            certAlipayRequest.setRootCertPath(alipay_root_cert_path);
            //构造client
            AlipayClient alipayClient = new DefaultAlipayClient(certAlipayRequest);

//            AlipayClient alipayClient = new DefaultAlipayClient(serverurl, app_id, private_key, format, charset, alipay_public_key, sign_type);
//            AlipayClient alipayClient = new DefaultAlipayClient(url, yrTaxSourcePayChannel.getPatParam3(), yrTaxSourcePayChannel.getPatParam2(), format, charset, yrTaxSourcePayChannel.getPatParam1(), yrTaxSourcePayChannel.getPatParam5());

            AlipayDataBillEreceiptQueryRequest request = new AlipayDataBillEreceiptQueryRequest();
            request.setBizContent("{" +
                    "\"file_id\":\"" + fileId + "\"" +
                    "  }");
            logger.info("查询电子回单状态接口传参" + request);
            AlipayDataBillEreceiptQueryResponse response = alipayClient.certificateExecute(request);
            logger.info("查询电子回单状态接口结果" + response);

            //网关返回码
            String code = response.getCode();
            //网关返回码描述
            String msg = response.getSubMsg();

            if (StringUtils.isNotBlank(code)) {
                if ("10000".equals(code)) {
                    String status = response.getStatus();
                    if ("SUCCESS".equals(status)) {
                        //查询成功
                        map.put("code", 1);
                        map.put("msg", response.getSubMsg());
                        map.put("url", response.getDownloadUrl());
                        map.put("error", response.getErrorMessage());
                        logger.info("查询电子回单状态接口结果" + map);

                    } else if ("INIT".equals(status)) {
                        //查询状态为初始化
                        map.put("code", 5);
                        map.put("msg", "查询初始化,请稍等");

                    } else if ("PROCESS".equals(status)) {
                        //查询状态为处理中
                        map.put("code", 5);
                        map.put("msg", "查询处理中,请稍等");

                    } else if ("FAIL".equals(status)) {
                        //查询状态失败
                        map.put("code", 4);
                        map.put("msg", "查询失败");

                    }
                } else {
                    map.put("code", 4);
                    map.put("msg", "查询失败");
                    //查询失败,返回码不为10000

                }
            } else {
                map.put("code", 4);
                map.put("msg", "获取返回码失败,查询失败");

            }


        } catch (Exception e) {
            e.printStackTrace();
            map.put("code", 4);
            map.put("msg", e.getMessage());

        }
        return map;
    }


    /**
     * 支付宝商家账户充值，转账，提现查询接口
     *
     * @param page_no
     * @param yrTaxSourcePayChannel
     * @return
     */
    public static Map<String, Object> transfeQuery(YrTaxSourcePayChannel yrTaxSourcePayChannel, int page_no) {

        String start_time = "2020-10-01 00:00:00";      //查询的起始时间
//        String end_time = "2020-09-01 23:59:59";        //查询的结束时间  起始时间和结束时间的时间间隔不得超过31天,是左闭右开区间
        String type = "DEPOSIT";                        //转账类型：充值-DEPOSIT 提现-WITHDRAW 转账-TRANSFER
//        String page_no = "1";                           //分页号，从1开始
        String page_size = "1000";                      //分页大小1000-2000，默认1000

        Date begTime = DateUtils.getDayBegin();
        Date endTime = DateUtils.getDayEnd();

//        //起始时间
//        DateFormat format1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//        String start_time = format1.format(begTime);

        //结束时间
        DateFormat format2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String end_time = format2.format(endTime);

        Map<String, Object> map = new HashMap<>();

        try {

            String url = ResourceUtil.getConfigByName("a_li_pay_url");
            //构造client
            CertAlipayRequest certAlipayRequest = new CertAlipayRequest();
            //设置网关地址
            certAlipayRequest.setServerUrl(url);
            //设置应用Id
            certAlipayRequest.setAppId(yrTaxSourcePayChannel.getPatParam3());
            //设置应用私钥
            certAlipayRequest.setPrivateKey(yrTaxSourcePayChannel.getPatParam2());
            //设置请求格式，固定值json
            certAlipayRequest.setFormat(format);
            //设置字符集
            certAlipayRequest.setCharset(charset);
            //设置签名类型
            certAlipayRequest.setSignType(yrTaxSourcePayChannel.getPatParam5());
            //设置应用公钥证书路径
            String app_cert_path = yrTaxSourcePayChannel.getPatParam4();
            certAlipayRequest.setCertPath(app_cert_path);
            //设置支付宝公钥证书路径
            String alipay_cert_path = yrTaxSourcePayChannel.getPatParam6();
            certAlipayRequest.setAlipayPublicCertPath(alipay_cert_path);
            //设置支付宝根证书路径
            String alipay_root_cert_path = yrTaxSourcePayChannel.getReference1();
            certAlipayRequest.setRootCertPath(alipay_root_cert_path);
            //构造client
            AlipayClient alipayClient = new DefaultAlipayClient(certAlipayRequest);

//            AlipayClient alipayClient = new DefaultAlipayClient(serverurl, app_id, private_key, format, charset, alipay_public_key, sign_type);
//            AlipayClient alipayClient = new DefaultAlipayClient(url, yrTaxSourcePayChannel.getPatParam3(), yrTaxSourcePayChannel.getPatParam2(), format, charset, yrTaxSourcePayChannel.getPatParam1(), yrTaxSourcePayChannel.getPatParam5());

            AlipayDataBillTransferQueryRequest request = new AlipayDataBillTransferQueryRequest();

            request.setBizContent("{" +
                    "\"start_time\":\"" + start_time + "\"," +
                    "\"end_time\":\"" + end_time + "\"," +
                    "\"type\":\"" + type + "\"," +
                    "\"page_no\":\"" + page_no + "\"," +
                    "\"page_size\":\"" + page_size + "\"" +
                    "  }");

            logger.info("支付宝商家账户充值，转账，提现查询接口传参" + request.getBizContent());
            AlipayDataBillTransferQueryResponse response = alipayClient.certificateExecute(request);
            logger.info("支付宝商家账户充值，转账，提现查询接口结果" + response.getBody());

            //网关返回码
            String code = response.getCode();
            //网关返回码状态
            String msg = response.getSubMsg();
            if (StringUtils.isNotBlank(code)) {
                if ("10000".equals(code)) {
                    //查询成功
                    map.put("code", 1);
                    map.put("msg", "查询成功");
                    map.put("total", response.getTotalSize());
                    List<TransferDetailResult> list = response.getDetailList();
                    ArrayList list1 = new ArrayList();
                    for (TransferDetailResult tdr : list) {
                        if ("成功".equals(tdr.getStatus())) {
                            Map<String, Object> res = new HashMap<>();
                            //业务订单号
                            res.put("orderNo", tdr.getOrderNo());
                            //打款金额
                            res.put("amount", tdr.getAmount());
                            //备注信息
                            res.put("memo", tdr.getMemo());

                            list1.add(res);

                        }
                    }
                    map.put("data", list1);

                } else {
                    //查询失败
                    map.put("code", 4);
                    map.put("msg", "查询失败");

                }
            } else {
                //获取返回码失败
                map.put("code", 4);
                map.put("msg", "获取返回码失败,查询失败");

            }
        } catch (Exception e) {
            e.printStackTrace();
            map.put("code", 4);
            map.put("msg", e.getMessage());

        }
        return map;
    }

    public static void main(String[] args) {
        YrPaymentOrder yrPaymentOrder= new YrPaymentOrder();
        YrTaxSourcePayChannel payChannel= new YrTaxSourcePayChannel();
        YrMerchantCapitalAccount yrMerchantCapitalAccount = new YrMerchantCapitalAccount();
        try {
            yrMerchantCapitalAccount.setReference11("20033");
            payChannel.setPatParam1("MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAjOF23DVl0ubK0T9xceQiCVbc8NWe0NDhEG1/1r9VE1bYQGy3t5E7dzZ+YcHvNuHG9HRrSiMSHmd+h59nR5N7Re2/P2OfG5xlZ58L/f68A3aK5+molEBtDxuJo2bJnbfB+hQdMgQC2WQS0s/sdJc0IURNgzbxo2ohV4Tt5R/VGXedxwFA5ixDdZIsPVmm5UUMkpvke0Ijf/Xpjq5MrbazDTMz5Q/lH0943j2+t3LvTIprYBwIwlDOtKhuxLTuDPJi8/8e/Aw9x05Uayk9PT3d4NF9YMR5dUpqKMMGlGZiX22yIAd3jdB/HjzvJ05SuGgEkX+6TzL47dma9YWmuOtFUQIDAQAB");
            payChannel.setPatParam2("MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCWaCkzzEfsV9hV2rx0Fo+xdvSIFPmmqA8fXG6Z1kNEf4AKDMZ2VUY1YP3maTxqkiaib21KnpxsMXc7JQJiw1+Yqnya/6xtrwfbcDLYpGx9wqtHqgGO69HN1x+LeZ4EZ2h4/g3bY6KF8astD33W+jUMyD54pynuZaJM5VKR1RyzK7PdJ9YubOgESiF0fCUHxeE5Q3lGNx9YRw3vMkDJYpkB6B7AvbRtvKjB+0QYmuCUuYnYEEpM8CfsubyRZj6Jly7BzS4iQL87eU3gLwtOXmbDE9nItzt92cHOJPexNaFrZWe7B/Tq8Myo9/CwwK/JNKiEJokiDCB81W4u9r8a4u85AgMBAAECggEARVFkC9dOHoKt1YOl7uqm9ucX88+W71PtBEsZPhUdk2gfnoIcxVSvstIsshA2I/ePjrVD7WwEM2joxn1cCCB64mVQYC8NTM+qE1w2UtoUljEtty2G4lOUsgU/KIy4Ytc1su2DfWUB9jFW7sGBAZ727BktkXWZQaHdlwrpbwSE4Z3AjiFiZVRTViKAFS9rV+tmZ6xs24LmMD1HqXUcDlVl2U/uQx1fcAjNAHqFmlR1ZhSIIA3uWW83wATNYg/ytlBJT8GybjnyB/xI5+CMnv82CXRJwGI4f9DhpBhDHpWC9SmLePNcQKaUGpMUU0RR7jUYYs4dU+CG0GuZBsYX8gVoAQKBgQDb91w3yUsQu1P5jPEjqQXRIE4VkDYwjimjYcC75FZlU4q8U1WTGpplYqTb7pr4UP0XrOf+myp2aYf36jMiCs69N0yjl0DuECSgxGAB5GnufipNyWHwVGfWiqpQ994jlblAmnIqE5ZJ1vfLx4dLpUs4tddKcpADU1cv900f39KDQQKBgQCvC7dXJGwvI+PlupeULMEYGz1trc0dacSGIE3F0sMBEz6SCPS0E/iNz+YaavCekoKFdE1dblOIXGepZ6ePk3jgeHlnLtkqa0B2bAtYeqL1bsM1pCs2dsP8PZkI6pAypkWoyMlqhfZ9yv1W7oHu2V4tDVj5TbGFm8r8mG26A1EF+QKBgQCnkDOLu6eXQ1yhCaDYTXXE7RsOiiD9tA48C8dKWpMF9TIGbGUP/oAHI7H6aDVdXDSwyGKiLYmXUqTlUl9JW3pJ4cpcBGjN8TY10eJhDqMzrqCDSRl2fpXrdQ5xR6DM8s2ATScSroEaFswFTCXgljZLKRqr98GFBwOv4m+6DELNAQKBgQCLXVahKLyBY5/EfaTFMkSiPr3PnvqZmmX/K6UABWeAaaP9fOfmn6fasFVRXycn+Rm1yvz1kCste/SEaaR8qTsp7IEr5567KRzvq+H0ld88bO06vfQxrqknIJvA/4/C46K+WO4Tw4iWapD9L3N/iMx0LhZSlsrpxzn7lhh2asGNcQKBgA/QhR7pVDgBFJhNZzwHQF+iwyN6cAjSJw5YXXIXY4eDfGbO4bWnEnXfeAnfD4njqbIznKQCDXsNEqUKUNA9BWaSyEHChxrSsdqugnKG/ii4PDbaEpZFH8SvFbqYu5uLvo7BMciyz/MhMn5XMaOes5Veft3p1ZvSj99Iea7VyiLh");
            payChannel.setPatParam3("2021001196693365");
            payChannel.setPatParam4("D:/svn/sc/qj-hqsc/upms/upms-server/src/main/webapp/resources/hqsc/templete/appCertPublicKey_2021001196693365.crt");
            payChannel.setPatParam5("RSA2");
            payChannel.setPatParam6("D:/svn/sc/qj-hqsc/upms/upms-server/src/main/webapp/resources/hqsc/templete/alipayCertPublicKey_RSA2.crt");
            payChannel.setReference1("D:/svn/sc/qj-hqsc/upms/upms-server/src/main/webapp/resources/hqsc/templete/alipayRootCert.crt");
            payChannel.setAccountName("13195301040013648");
            payChannel.setTaxSourceId(1L);
            yrPaymentOrder.setMerchantOrderNumber("420201010165756314000002");
            yrPaymentOrder.setAmountOfPayment(new BigDecimal(100));
            yrPaymentOrder.setReceivingAccount("6225880280120198");
            yrPaymentOrder.setNameOfReceiver("喵星人");
            yrPaymentOrder.setMerchantId(63L);
            yrPaymentOrder.setPaymentOrderId(1L);
            yrPaymentOrder.setCapitalFlowNumber("20201010110070000006430076348026");
            yrPaymentOrder.setRepresentativeAgent("20201010110070001506430093672009");
            yrPaymentOrder.setReference17("17718482");

            SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date date=new Date();
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(date);
            calendar.add(Calendar.DAY_OF_MONTH, -1);
            date = calendar.getTime();
//            ereceiptApply(yrPaymentOrder.getRepresentativeAgent(),payChannel);
//            ereceiptQuery(yrPaymentOrder.getReference17(),payChannel);
            transfeQuery(payChannel,1);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
